#include <string>
#include <vector>
#include "errors.h"
#include "cmd.h"

namespace cmd
{
	static bool HelpOption;
	static bool OnlyOption;
	static bool LexerOption;
	static bool ParseExpressionsOption;
	static bool ParseExpressions2Option;

	static std::string filename;
	static std::vector<const std::string> options;
	void WrongSyntax()
	{
		HelpOption = true;
		throw CCompiler::Errors::CmdOptionsError();
	}
	void ParseCmd(int argc, char *argv[])
	{
		for(int i = 1; i < argc; ++i)
			options.push_back(argv[i]);
		for(size_t i = 0; i < options.size(); ++i)
		{
			if(options[i].substr(0, 2) != "--")
			{
				if(!filename.empty()) WrongSyntax();
				filename = options[i];
			}
			else if(options[i] == "--tokenizer-only")
			{
				if(OnlyOption) WrongSyntax();
				LexerOption = OnlyOption = true;
			}
			else if(options[i] == "--expressions-parser-only")
			{
				if(OnlyOption) WrongSyntax();
				ParseExpressionsOption = OnlyOption = true;
			}
			else if(options[i] == "--expressions-parser2-only")
			{
				if(OnlyOption) WrongSyntax();
				ParseExpressions2Option = OnlyOption = true;
			}
		}
	}
	bool NeedToPrintHelp()
	{
		return options.empty() || HelpOption;
	}
	bool LexerOptionEnabled()
	{
		return LexerOption;
	}
	bool ParseExpressionsOptionEnabled()
	{
		return ParseExpressionsOption;
	}
	bool ParseExpressions2OptionEnabled()
	{
		return ParseExpressions2Option;
	}
	bool OnlyOptionEnabled()
	{
		return OnlyOption;
	}
	std::string GetFilename()
	{
		return filename;
	}
}

